package com.cloud.system.api.web;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.cloud.system.api.entity.SysInfo;
import com.cloud.system.api.service.SysInfoService;
import com.cloud.system.common.result.Quokka;

@RestController
@RequestMapping("system/api/info")
public class SystemInfoController {

	@Autowired
	private SysInfoService sysInfoService;

	@RequestMapping("/listtree")
	public Quokka listSysInfo() {
		return new Quokka(true, sysInfoService.listSysInfo());
	}

	@RequestMapping("/load")
	public Quokka load(@RequestParam(required = true) long id, HttpServletRequest req) {
		return new Quokka(true, sysInfoService.loadSysInfo(id));
	}

	@RequestMapping("/saveupdate")
	public Quokka saveUpdateSysInfo(@RequestBody(required = true) SysInfo sysInfo) {
		return new Quokka(true, sysInfoService.saveUpdateSysInfo(sysInfo));
	}

	@RequestMapping("/delete")
	public Quokka deleteSysInfo(@RequestParam(required = true) long id) {
		sysInfoService.deleteSysInfo(id);
		return new Quokka(true);
	}

	@RequestMapping("/update")
	public Quokka updateSysInfo(SysInfo sysInfo) {
		sysInfoService.updateSysInfo(sysInfo);
		return new Quokka(true);
	}

	@GetMapping("/getinitsystembyurl")
	public Quokka getInitSystemByUrl(String url){
		return new Quokka(true, sysInfoService.getInitSystemByUrl(url));
	}

	@RequestMapping("/basisUpdate")
	public Quokka basisUpdateSysInfo(){
		return new Quokka(true,sysInfoService.basisUpdateSysInfo());
	}
}
